package service

func searchInsert(nums []int, target int) int {
	if len(nums) == 0 {
		return 0
	}
	if target < nums[0] {
		return 0
	}
	if target > nums[len(nums)-1] {
		return len(nums)
	}
	l := 0
	r := len(nums) - 1
	n := 0
	for {
		mid := (l + r + 1) / 2
		if mid == l {
			n = mid
			break
		}
		if target <= nums[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}

	return n
}
